package com.lg.system.log.controller;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.lg.common.annotation.Logs;
import com.lg.common.base.BaseController;
import com.lg.common.validate.Delete;
import com.lg.system.log.entity.Log;
import com.lg.system.log.service.LogService;
import com.lg.system.user.entity.UserEntity;
import com.lg.utils.PageModel;
import com.lg.utils.Query;
import com.lg.utils.R;

/**
 * <p>
 * 系统日志 前端控制器
 * </p>
 *
 * @author dl
 * @since 2018-03-27
 */
@RestController
@RequestMapping("/log")
public class LogController extends BaseController<Log, LogService> {

	private String prefix="system/log/";
	
	@Autowired
	LogService logService;
	
	@RequiresPermissions("log:log")
	@GetMapping("index")
	public ModelAndView index(){
		ModelAndView mView=new ModelAndView(prefix+"index");
		return mView;
	}
	
	@RequiresPermissions("log:log")
	@RequestMapping("/list")
	public PageModel selectList(@RequestBody Log log){
		Query<Log> query = new Query<Log>(log);
		List<Log> users=logService.selectList(query.getEntityWrapper());
		PageModel pa=new PageModel(users,query.getPage().getTotal());
		return pa;
	}
	
	@RequiresPermissions("log:del")
	@PostMapping("/deleteRow")
	public R deleteRow(@RequestBody @Validated(value={Delete.class}) Log log,BindingResult bindingResult){
		if(logService.deleteById(log.getId())){
			return R.ok();
		}else{
			return R.error();
		}
	}
	
	@RequiresPermissions("log:del")
	@PostMapping("/deleteRows")
	public R deleteRows(@RequestParam(value="ids[]") List<Long> ids){
		if(logService.deleteBatchIds(ids)){
			return R.ok();
		}else{
			return R.error();
		}
	}
	
}
